﻿using System;
using System.Reflection;

namespace Sapit.Helpers
{
    public static class AttributeHelper
    {
        public static T GetAttributeIfPresent<T>(MethodBase methodBase) where T : class
        {
            var attributes = methodBase.GetCustomAttributes(typeof(T), false);
            if (attributes != null && attributes.Length > 0)
            {
                return attributes[0] as T;
            }
            else
            {
                return null;
            }
        }

        public static bool HasAttribute<AttributeT>(Type type)
        {
            var attributes = type.GetCustomAttributes(typeof(AttributeT), true);
            return attributes != null && attributes.Length > 0;
        }
    }
}
